import axios, { AxiosInstance,  AxiosResponse } from 'axios';
// 返回res.data的interface
export interface IResponse {
    code: number | string;
    data: any;
    msg: string;
}
let axiosInstance: AxiosInstance = axios.create({
    baseURL: " http://localhost:8000/",
    headers: {
        Accept: "application/json",
        "Content-Type": "application/x-www-form-urlencoded"
    },
});
// axios实例拦截响应
axiosInstance.interceptors.response.use(
    (response: AxiosResponse) => {
        if (response.headers.authorization) {
            localStorage.setItem('app_token', response.headers.authorization);
        } else {
            if (response.data && response.data.token) {
                localStorage.setItem('app_token', response.data.token);
            }
        }
        if (response.status === 200) {
            return response;
        } else {
            console.log('error');
        }
    },
);
export default axiosInstance;